
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0046)http://localhost:8080/admin/goods_spec_add.htm -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title></title>
<link href="/css/template.css" rel="stylesheet" type="text/css">
<link href="/css/overlay.css" type="text/css" rel="stylesheet">
<script src="/js/jquery-1.6.2.js"></script>
<script src="/js/jquery-ui-1.8.21.js"></script>
<script src="/js/jquery.shop.common.js"></script>
<script src="/js/jquery.validate.min.js"></script>
<script src="/js/jquery.poshytip.min.js"></script>
<script>
$(function(){
	$("input[id=buttoninput]").click(function(){
		var name = $("input[id=name]").val();
		if(name == "")
		{
			$("label").html("规格名称不能为空");
			$('html , body').animate({scrollTop: 0},'slow');//回到页面顶部 
			
			$('input[id=name]').css('border','1px solid red');//修改文本框边框颜色
			$('input[id=name]').css('outline','none');//去掉边框轮廓
		}
		else
		{
			$.ajax({//去后台验证规格名称是否存在
	 			url:'/goodsspec/yanzhengname',
	 			type:'post',
	 			async:true,
	 			data:{
	 				'name':name
	 			},
	 			success:function(data){
	 				$("label").html(data);
	 				var yanzheng1 = $("input[id=yanzheng1]").val();
	 				if(yanzheng1 == 1)
	 				{
						$('html , body').animate({scrollTop: 0},'slow');//回到页面顶部 
	 					
	 					$('input[id=name]').css('border','1px solid red');//修改文本框边框颜色
	 		  			$('input[id=name]').css('outline','none');//去掉边框轮廓
	 				}
	 				else
	 				{
	 					//获取新规格名
	 		  			var newname = $("input[id=name]").val();
	 		  			//获取规格的排序
	 		  			var typepx = $("input[id=sequence]").val();
	 		  			if(typepx == "")
	 		  			{
	 		  				typepx = 0;
	 		  			}
	 		  			else if(isNaN(typepx))
	 		  			{
	 		  				typepx = 0;
	 		  			}
	 		  			var type1 = $("input[id=type1]").attr("checked");
	 		  			if(type1 == "checked")
	 		  			{
	 		  				type1 = "text";
	 		  			}
	 		  			else
	 		  			{
	 		  				type1 = "img";
	 		  			}
	 		  			$.ajax({
	 		  				url:'/goodsspec/addifi',//向shopping_goodsspecification加规格名称 和 排序
	 		  				type:'post',
	 		  				async:false,
	 		  				scriptCharset:'utf-8',
	 		  				data:{
	 		  					name:newname,
	 		  					sequence:typepx,
	 		  					type:type1
	 		  				},
	 		  				success:function(data){
	 		  					$("span[id=hqtypeid]").html(data);
	 		  					var yanzheng2 = $("input[id=yanzheng2]").val();//spec_id
	 		  					var yanzheng3 = $("input[id=yanzheng3]").val();//type
	 		  					
	 		  					var addggpx;//排序
	 		  					var addggname;//规格值名
	 		  					var addggimg;//图片名
	 		  					$.each($('input[class=addggname]'),function(i){
	 		  						addggname =$(this).val();
	 		  						addggpx =$(this).parent().parent().parent().children().children().children(".addggpx").val();
	 		  						addggimg =$(this).parent().parent().parent().children().children().children(".addggimg").val();
	 		  						if(addggname != "")
		 	 		  				{
			 	 		  				if(addggpx == "")
			 	 	 		  			{
			 	 		  					addggpx = 0;
			 	 	 		  			}
			 	 	 		  			else if(isNaN(addggpx))
			 	 	 		  			{
			 	 	 		  				addggpx = 0;
			 	 	 		  			}
				 	 		  			$.ajax({
			 	 		  	 	 			url:'/goodsspec/selectimg',
			 	 		  	 	 			type:'post',
			 	 		  	 	 			async:false,
			 	 		  	 	 			data:{},
			 	 		  	 	 			success:function(data){
			 	 		  	 	 				$("span[id=selectimg]").html(data);
				 	 		  	 	 			addggimg = "4"+parseInt(Math.random()*10)+parseInt(Math.random()*10)+parseInt(Math.random()*10)+parseInt(Math.random()*10)+parseInt(Math.random()*10);
				 	 		  	 	 			$.each($("input[class=selectimg02]"),function(i){
					 	 		  		 			ch =$(this).val();
					 	 		  		 			if(ch == addggimg)
					 	 		  		 			{
					 	 		  		 				addggimg = "4"+parseInt(Math.random()*10)+parseInt(Math.random()*10)+parseInt(Math.random()*10)+parseInt(Math.random()*10)+parseInt(Math.random()*10);
					 	 		  		 			}
					 	 		  		 		});
					 	 		  	 	 		$.ajax({
					 	 		  	 	 			url:'/goodsspec/addgg',
					 	 		  	 	 			type:'post',
					 	 		  	 	 			async:false,
					 	 		  	 	 			data:{
					 	 		  	 	 				name:addggname,
					 	 		  	 	 				sequence:addggpx,
					 	 		  	 	 				img:addggimg,
					 	 		  	 	 				spec_id:yanzheng2
					 	 		  	 	 			},
					 	 		  	 	 			success:function(data){
					 	 		  	 	 				$("span[id=imgid]").html(data);
					 	 		  	 	 				var xx = $("input[class=imgid]").val();
					 	 		  	 	 				alert(xx);
					 	 		  	 	 			}
					 	 		  	 	 		});
				 	 		  	 	 			
			 	 		  	 	 			}
			 	 		  	 	 		});
			 	 		  				
			 	 		  				
			 	 		  			
		 	 		  				}
	 		  						
	 		  					});
	 		  					
	 		  				}
	 		  			});
	 				}
	 			}
	 		});
		}
	});
});
// jQuery(document).ready(function(){
//   jQuery("#theForm").validate({
//     rules:{
// 	  name:{
// 	    required :true,
// 	     remote:{
// 		    url: "http://localhost:8080/admin/goods_spec_verify.htm",     //后台处理程序
//             type: "post",               //数据发送方式
//             dataType: "json",           //接受数据格式   
//             data: {                     //要传递的数据
//                   "name": function(){return jQuery("#name").val();},
// 				  "id":function(){return jQuery("#id").val()}
// 		     }
// 			}
// 	  }
// 	 },
// 	messages:{
// 	  name:{required:"规格名称不能为空",remote:"该规格已经存在"}
// 	}
//   });
//   });
function saveForm(){
	jQuery("#count").val(count);
	jQuery("#theForm").submit();
}
function change_img(obj){
  var sequence=jQuery(obj).attr("id").substring(10);
  var path=jQuery(obj).val();
  var src=getFullPath(jQuery(obj)[0]);
  jQuery("#image_"+sequence).attr("src",src);
  jQuery("#textfield_"+sequence).val(path);
}
</script>
<style id="poshytip-css-tip-skyblue" type="text/css">div.tip-skyblue{visibility:hidden;position:absolute;top:0;left:0;}div.tip-skyblue table, div.tip-skyblue td{margin:0;font-family:inherit;font-size:inherit;font-weight:inherit;font-style:inherit;font-variant:inherit;}div.tip-skyblue td.tip-bg-image span{display:block;font:1px/1px sans-serif;height:10px;width:10px;overflow:hidden;}div.tip-skyblue td.tip-right{background-position:100% 0;}div.tip-skyblue td.tip-bottom{background-position:100% 100%;}div.tip-skyblue td.tip-left{background-position:0 100%;}div.tip-skyblue div.tip-inner{background-position:-10px -10px;}div.tip-skyblue div.tip-arrow{visibility:hidden;position:absolute;overflow:hidden;font:1px/1px sans-serif;}</style></head>
<body>
<form action="/goodsspec/form" method="post" enctype="multipart/form-data" name="theForm" id="theForm">
<!-- novalidate="novalidate" -->
  <input name="id" id="id" type="hidden" value="">
  <input name="add_url" type="hidden" id="add_url" value="http://localhost:8080/admin/goods_spec_add.htm">
  <input name="list_url" type="hidden" id="list_url" value="http://localhost:8080/admin/goods_spec_list.htm">
  <input name="count" type="hidden" id="count">
  <span id="hqtypeid"></span>
  <span id="selectimg"></span>
  <span id="imgid"></span>
  <div class="cont">
    <h1 class="seth1">规格管理</h1>
    <div class="settab"><span class="tab-one"></span> <span class="tabs"> <a href="/dispatcher/dispatch?dispatch_url=goods_spec_list.html">管理</a> | <a href="/dispatcher/dispatch?dispatch_url=goods_spec_add.html" class="this">新增</a> </span> <span class="tab-two"></span></div>
    <div class="edit">
      <div class="editul ">
        <ul class="set3">
          <li><strong class="sred">*</strong>规格名称</li>
          <li><span class="pxnum">
            <input name="name" type="text" id="name" value="">
            
            </span><span><label for="name" generated="true" class="error"></label></span><span id="nothis"><strong class="q"></strong><strong class="w">请填写常用的商品规格的名称；例如：颜色；尺寸等。</strong><strong class="c"></strong></span></li>
        </ul>
        <ul class="set3">
          <li>排序</li>
          <li><span class="pxnum">
         <input name="sequence" type="text" id="sequence" value="">
            </span><span id="this"><strong class="q"></strong><strong class="w">请填写整数。类型列表将会根据排序进行由小到大排列显示。</strong><strong class="c"></strong></span></li>
        </ul>
      </div>
      <div class="spec_type">
        <h3>规格类型</h3>
        <ul class="set3">
         <li>
		  <span class="ssp1">
            <input name="type" type="radio" id="type1" value="text" checked="checked" onclick="img_spec(&#39;0&#39;)">
            文字</span><span class="ssp2">
            <input name="type" id="type2" type="radio" value="img" onclick="img_spec(&#39;1&#39;)">
            图片</span><span id="nothis"><strong class="q"></strong><strong class="w">图片类型的规格值用于直观表现某些特殊规格类型，例如颜色规格，可用对应的色彩图片来表现其各种颜色值。</strong><strong class="c"></strong>
			</span>
		</li>
       </ul>
      </div>
<script>
var count=1;
function img_spec(status){
  if(status=="1"){
    jQuery("span[id^=goods_spec_property_img_]").show();
  }
  if(status=="0"){
    jQuery("span[id^=goods_spec_property_img_]").hide();
  }
}
function remove_goods_spec_property(obj,id){
   jQuery.post("http://localhost:8080/admin/goods_property_delete.htm",{"id":id},function(data){
     if(data=="true"){
	    jQuery(obj).remove();
        count--;
	 }else alert("规格值删除失败！");
   },"text");
}
function add_goods_spec_property(){
count++;
 var goods_spec_property_img="<tr id='goods_spec_'><td width='82'><span class='pxnum size5'><input name='sequence_count' class='addggpx' id='sequence_count' value='' type='text'></span></td><td width='271'><span class='pxnum size7'><input name='value_count' class='addggname' id='value_count' value='' type='text'></span></td><td class='liul' width='558'><span id='goods_spec_property_img_' class='size13'><input name='textfield_count' id='textfield_count' type='text'></span> <span class='filebtn' id='goods_spec_property_img_'><input name='button' id='button1' value='' type='button'></span> <span id='goods_spec_property_img_' style='float:left;' class='file'><input name='specImage' id='specImage_count' size='30' type='file' class='addggimg' onchange='change_img(this);'></span><span id='goods_spec_property_img_' class='pic_spe'><img id='image_count' name='image_count' src='/shopping/resources/style/common/images/transparent.gif' height='16' width='16'></span></td><td class='ac8' align='center' width='116'><a href='javascript:void(0);' onclick='remove_goods_spec_property(this.parentNode.parentNode,\"\")'>删除</a></td></tr>";
  var goods_spec_property_text="<tr id='goods_spec_'><td width='82'><span class='pxnum size5'><input name='sequence_count' class='addggpx' id='sequence_count' value='' type='text'></span></td><td width='271'><span class='pxnum size7'><input name='value_count' class=addggname' id='value_count' value='' type='text'></span></td><td class='liul' width='558'><span id='goods_spec_property_img_' style='display:none;' class='size13'><input name='textfield_count' id='textfield_count' type='text'></span> <span class='filebtn' id='goods_spec_property_img_'  style='display:none;'><input name='button' id='button1' value='' type='button'></span> <span id='goods_spec_property_img_'  style='float:left;display:none;' class='file'><input name='specImage_count' id='specImage_count' size='30' type='file' class='addggimg'  onchange='change_img(this);'></span><span id='goods_spec_property_img_'  style='display:none;' class='pic_spe'><img   id='image_count' name='image_count' src='/shopping/resources/style/common/images/transparent.gif' height='16' width='16'></span></td><td class='ac8' align='center' width='116'><a href='javascript:void(0);' onclick='remove_goods_spec_property(this.parentNode.parentNode,\"\")'>删除</a></td></tr>";
  var type=jQuery(":radio:checked").val();
  if(type=="img"){
    jQuery(".addsx_table tr[id^=goods_spec_]").last().after(goods_spec_property_img.replace(/count/g,count));
  }else{
    jQuery(".addsx_table tr[id^=goods_spec_]").last().after(goods_spec_property_text.replace(/count/g,count));
  }
}
</script>
      <div class="specification">
        <h2>新增规格值</h2>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="addsx_table">
          <tbody><tr id="goods_spec_">
            <td width="82"><strong>排序</strong></td>
            <td width="271"><strong>规格值</strong></td>
            <td width="558"><strong><span id="goods_spec_property_img_" style="display:none;">规格图片</span></strong></td>
            <td align="center">操作</td>
          </tr>
		            <tr id="goods_spec_property">
            <td width="82"><span class="pxnum size5">
            <input name="sequence_1" class="addggpx" type="text" id="sequence_1" value="">
              </span></td>
            <td width="271"><span class="pxnum size7">
              <input name="value_1" class="addggname" type="text" id="value_1" value="">
              </span></td>
            <td width="558" class="liul"><span class="size13" id="goods_spec_property_img_" style="display:none;">
              <input name="textfield_1" type="text" id="textfield_1">
              </span> <span class="filebtn" id="goods_spec_property_img_" style="display:none;">
              <input name="button" type="button" id="button1" value="">
              </span> <span style="float:left;" class="file">
              <input name="specImage" class="addggimg" type="file" id="specImage_1" size="30" onchange="change_img(this);">
              </span> 
			  <span class="pic_spe" id="goods_spec_property_img_" style="display:none;"><img id="image_1" name="image_1" src="./transparent.gif" width="16" height="16"></span>		    </td>
            <td width="116" align="center" class="ac8"><a href="javascript:void(0);" onclick="remove_goods_spec_property(this.parentNode.parentNode,&#39;&#39;)">删除</a></td>
          </tr>
		            <tr>
            <td colspan="3"><span class="newclass"><a href="javascript:void(0);" onclick="add_goods_spec_property();">新增规格值</a></span></td>
            <td>&nbsp;</td>
          </tr>
        </tbody></table>
      </div>

	</div>
    <div class="submit">
      <input name="" id="buttoninput" type="button" value="提交" onclick="saveForm();">
    </div>
  </div>
</form>


</body></html>